import axios from "axios";
import {useUserStore} from "@/store/modules/user";

const request = axios.create({
    baseURL: "http://sph-api.atguigu.cn",
    timeout: 5000
})
// 请求拦截器
request.interceptors.response.use(config => {
    let userStore = useUserStore()
    if (userStore.token) {
        config.headers.token = userStore.token
    }
    return config

})
// 响应拦截器
request.interceptors.response.use(res => {
    return res.data

}, err => {

    return Promise.reject(err)
})
export default request;